Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

q3-core-responder

Package Overview
Dependencies
Maintainers
1
Versions
261
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

q3-core-responder

Q3 responder handles two responsibilities: (1) assigning HTTP status codes to unhandled exceptions and (2) throwing custom errors in the stack. Within client projects, the first is irrelevant as Q3 registers the functionality via global express middle

  • 1.25.1
  • npm
  • Socket score

Version published
Weekly downloads
31
increased by342.86%
Maintainers
1
Weekly downloads
 
Created
Source

Responder

Q3 responder handles two responsibilities: (1) assigning HTTP status codes to unhandled exceptions and (2) throwing custom errors in the stack. Within client projects, the first is irrelevant as Q3 registers the functionality via global express middleware. However, the second is very common when dealing with custom validation logic.

API

exception

The exception export offers a chainable API for building general and field-level errors. When constructing, the first parameter will correspond to an HTTP status code (see table below).

ErrorCode
BadRequest400
Authentication401
Authorization403
ResourceNotFound404
Conflict409
Gone410
Preprocessing412
Validation422
InternalServer500

Afterwards, you can chain the following methods. You can invoke msg and field in any order but boomerang, log and throw should end your chain.

MethodParamDescription
msgStringThe language key for a message to decorate the HTTP response
fieldString or ObjectThe field-level error to report. If a string, it will duplicate the msg output. If an object, you can provide custom messages and map to multiple fields.
throwA custom error will throw in your stack
boomerangA custom error will return
logA custom error will log to console
Example
const { exception } = require('q3-core-responder');

function doSomething(args = {}) {
  if (args.bad)
    exception('Conflict')
      .msg('custom18nMessageKey')
      .field('name')
      .throw();

  if (args.reallyBad)
    exception('Validation')
      .msg('custom18nMessageKey')
      .field({
        in: 'application', // can be anything
        name: ['field1', 'field2'],
        msg: 'dataNoGood',
      })
      .throw();
}

FAQs

Package last updated on 03 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc